#include "ClientSdk.h"
#include "Manager.h"
#include "MiniDump.h"
//#include "FT_RY1S_API.h"

CManager *pMan = NULL;
bool g_bInit = false;
static MiniDumper minDump(true);

CLIENT_SDK_API int InitDll(int nTermialId, int nSpeakComId, int nElevatorComId, int nRatio, const char *pFileSavePath, OnMessageCallback callback, void *pUser)
{
	if (pMan)
	{ 
		delete pMan;
		pMan = NULL;
	}

	pMan = new CManager(nTermialId, nSpeakComId, nElevatorComId, nRatio, pFileSavePath, callback, pUser);
	if (!pMan)
		return -1;

	g_bInit = true;

	return 0;
}

CLIENT_SDK_API int CreateWb()
{
	if (!g_bInit || !pMan)
		return -1;

	pMan->CreateWb();

	return 0;
}	

CLIENT_SDK_API int ReleaseDll(void)
{
	if (pMan)
	{ 
		delete pMan;
		pMan = NULL;
	}

	g_bInit = false;

	return 0;
}

CLIENT_SDK_API int ChangeLanguage(int nLanguageType)
{
	if (!g_bInit || !pMan)
		return -1;

	pMan->ChangeLanguage(nLanguageType);
		
	return 0;
}

CLIENT_SDK_API int ReSetTerminalInfo(int nTermialId, const char *pSvrIp, unsigned short usPort)
{
	if (!g_bInit || !pMan)
		return -1;

	pMan->ReSetServerInfo(nTermialId, pSvrIp, usPort);

	return 0;
}

CLIENT_SDK_API int SetElevatorParam(int nBaudRate, const char *pDownCmd, const char *pUpCmd)
{
	if (!g_bInit || !pMan)
		return -1;

	pMan->SetElevatorParam(nBaudRate, pDownCmd, pUpCmd);

	return 0;
}

CLIENT_SDK_API int SetScreenBroadcastWindows(unsigned long ulPlayHandle)
{
	if (!g_bInit || !pMan)
		return -1;

	pMan->SetPlayWindows(ulPlayHandle);

	return 0;
}

CLIENT_SDK_API int ConnectServer(const char *pSvrIp, unsigned short usPort)
{
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->StartApp(pSvrIp, usPort))
		return 0;

	return -1;
}

CLIENT_SDK_API int Login(const char *pUserName, const char *pPassWord, char *pOutBuf, int *nBufLen)
{
	if (!g_bInit || !pMan)
		return false;

	return pMan->UserLogin(pUserName, pPassWord, pOutBuf, nBufLen);
}

CLIENT_SDK_API unsigned int GetWBWindowHandle(void)
{
	if (!g_bInit || !pMan)
		return -1;

	return pMan->GetWindowHandle();
}

CLIENT_SDK_API void ClearWbData(void)
{
	if (!g_bInit || !pMan)
		return ;

	pMan->ClearLocalWbData();
}

CLIENT_SDK_API void GetWbData(void)
{
	if (!g_bInit || !pMan)
		return ;

	pMan->GetWbData();
}

CLIENT_SDK_API void ClearSaveWbData(void)
{
	if (!g_bInit || !pMan)
		return ;

	pMan->ClearSaveWbData();
}

CLIENT_SDK_API void SetWbMode(bool bLocal)
{
	if (!g_bInit || !pMan)
		return ;

	pMan->SetWbMode(bLocal);
}

CLIENT_SDK_API int EnableDataOperationRight(bool bEnable)
{
	if (!g_bInit || !pMan)
		return -1;

	pMan->EnableDataOperationRight(bEnable);

	return 0;
}

CLIENT_SDK_API int EnadleSync(bool bEnable)
{
	if (!g_bInit || !pMan)
		return -1;

	pMan->EnadleSync(bEnable);

	return 0;
}

CLIENT_SDK_API int GetUserInfo(char *pOutBuf, int *nBufLen)
{	
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->GetUserInfo(pOutBuf, nBufLen))
		return 0;

	return -1;
}

CLIENT_SDK_API int GetUserList(char *pOutBuf, int *nBufLen)
{
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->GetUserList(pOutBuf, nBufLen))
		return 0;

	return -1;
}

CLIENT_SDK_API int GetMeetingFileList(char *pOutBuf, int *nBufLen)
{
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->GetMeetingFileList(pOutBuf, nBufLen))
		return 0;

	return -1;
}

CLIENT_SDK_API int GetMeetingIssueList(char *pOutBuf, int *nBufLen)
{
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->GetMeetingIssueList(pOutBuf, nBufLen))
		return 0;

	return -1;
}

CLIENT_SDK_API int GetMeetingVoteList(char *pOutBuf, int *nBufLen)
{
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->GetMeetingVoteList(pOutBuf, nBufLen))
		return 0;

	return -1;
}

CLIENT_SDK_API int TerminalUserSign(int nUserId, const char *pUserName, const char *pFilePath, const char *pFileName)
{
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->TerminalUserSign(nUserId, pUserName, pFilePath, pFileName))
		return 0;
	
	return -1;
}

CLIENT_SDK_API int UserSignControl(int nControlType)
{
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->UserSignControl(nControlType))
		return 0;

	return -1;
}

CLIENT_SDK_API int AllUserSign(const char *pMsgJson)
{
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->AllUserSign(pMsgJson))
		return 0;

	return -1;
}

CLIENT_SDK_API int OpenScreenBroadcast()
{
	if (!g_bInit || !pMan)
		return -1;

	return pMan->OpenScreenBroadcast();
}

CLIENT_SDK_API int InviteOpenScreenBroadcast(int nUserId, int nType, bool bForce)
{
	if (!g_bInit || !pMan)
		return -1;

	return pMan->InviteOpenScreenBroadcast(nUserId, nType, bForce);
}

CLIENT_SDK_API int CloseScreenBroadcast()
{
	if (!g_bInit || !pMan)
		return -1;

	return pMan->CloseScreenBroadcast();
}

CLIENT_SDK_API int DownLoadFile(const char *pSvrFilePath, const char *pSaveFilePath)
{
	if (!g_bInit || !pMan)
		return -1;

	return pMan->DownLoadFile(pSvrFilePath, pSaveFilePath);
}

CLIENT_SDK_API int UpLoadFile(const char *pFilePath, const char *pFileName, int nFileType)
{
	if (!g_bInit || !pMan)
		return -1;

	return pMan->UpLoadFile(pFilePath, pFileName, nFileType);
}

CLIENT_SDK_API int StopUpLoadFile(const char *pFilePath)
{
	if (!g_bInit || !pMan)
		return -1;

	return pMan->StopUpload(pFilePath);
}

CLIENT_SDK_API int SendChatMessage(const char *pChatMessage)
{
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->SendChatMessage(pChatMessage))
		return 0;

	return -1;
}

CLIENT_SDK_API int SendMeetingService(const char *pChatMessage)
{
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->SendMeetingService(pChatMessage))
		return 0;

	return -1;
}

CLIENT_SDK_API int StartWhiteBoard(int nUserId, char *pOutBuf, int *nBufLen)
{
	if (!g_bInit || !pMan)
		return -1;

	return pMan->StartWbRequest(nUserId, pOutBuf, nBufLen);
}

CLIENT_SDK_API int StopWhiteBoard(int nUserId)
{
	if (!g_bInit || !pMan)
		return -1;

	return pMan->CloseWb(nUserId);
}

CLIENT_SDK_API int IssueControl(int nIssueId, int nControlType)
{
	if (!g_bInit || !pMan)
		return -1;

	return pMan->IssueControl(nIssueId, nControlType);
}

CLIENT_SDK_API int VoteControl(int nVoteId, int nControlType)
{
	if (!g_bInit || !pMan)
		return -1;

	return pMan->VoteControl(nVoteId, nControlType);
}

CLIENT_SDK_API int VoteMsg(const char *pVoteJson, int nJsonLen)
{
	if (!g_bInit || !pMan)
		return -1;

	return pMan->VoteMsg(pVoteJson, nJsonLen);
}

CLIENT_SDK_API int CenterControl(int nControlType, const char *pTerminalId)
{
	if (!g_bInit || !pMan)
		return -1;

	return pMan->CenterControl(nControlType, pTerminalId);
}

CLIENT_SDK_API int InviteTerminalSpeak(int nTerminalId)
{
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->InviteTerminalSpeak(nTerminalId))
		return 0;
	
	return -2;
}

CLIENT_SDK_API int TerminalApplySpeak(bool bChairman)
{
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->TerminalApplySpeak(bChairman))
		return 0;

	return -2;
}

CLIENT_SDK_API int ApplaySpeakRsp(int nTerminalId, int nResult, const char *strError)
{
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->ApplaySpeakRsp(nTerminalId, nResult, strError))
		return 0;

	return -2;
}

CLIENT_SDK_API int StopSpeak(int nTerminalId)
{
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->StopSpeak(nTerminalId))
		return 0;

	return -2;
}

CLIENT_SDK_API int RequestDesktop(int nTerminalId)
{
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->RequestDesktop(nTerminalId))
		return 0;

	return -2;
}

CLIENT_SDK_API int RequestDesktopRsp(int nTerminalId, int nResult)
{
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->RequestDesktopRsp(nTerminalId, nResult))
		return 0;

	return -2;
}

CLIENT_SDK_API int PushDesktop(int nTerminalId)
{
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->PushDesktop(nTerminalId))
		return 0;

	return -2;
}

CLIENT_SDK_API int PushDesktopRsp(int nTerminalId, int nResult)
{
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->PushDesktopRsp(nTerminalId, nResult))
		return 0;

	return -2;
}

CLIENT_SDK_API int PushDesktopToScreen(int nTerminalId, const char *pScreen, int nType)
{
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->PushDesktopToScreen(nTerminalId, pScreen, nType))
		return 0;

	return -2;
}

CLIENT_SDK_API int PushDesktopToScreenRsp(const char *pScreen, int nResult)
{
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->PushDesktopToScreenRsp( pScreen, nResult))
		return 0;

	return -2;
}

CLIENT_SDK_API int CloseStream(int nInTerminalId, int nOutTerminalId)
{
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->CloseStream(nInTerminalId, nOutTerminalId))
		return 0;

	return -2;
}
